<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>微机原理（LEGACY） | Fusyōn.</title><meta name="author" content="i4N"><meta name="copyright" content="i4N"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="定时器8253 初始化首先计算计数初值，晶振频率为 $F_{osc}$，目标信号频率是 $f$ 计数初值绝对是大于1的，也就是 $$N &#x3D; \frac{F_{osc}}{f}$$如果计数器计数初值超过 FFFFH，说明 Fosc 太大，可以多设置一个定时器，用那个定时器的 OUT 代替晶振作为超过限制计数器的 CLK信号输入： $$ N &#x3D; \frac{f_{new}}{f}">
<meta property="og:type" content="article">
<meta property="og:title" content="微机原理（LEGACY）">
<meta property="og:url" content="http://jav1ki4n.github.io/2025/10/21/%E5%BE%AE%E6%9C%BA%E6%80%BB%E7%BB%93/index.html">
<meta property="og:site_name" content="Fusyōn.">
<meta property="og:description" content="定时器8253 初始化首先计算计数初值，晶振频率为 $F_{osc}$，目标信号频率是 $f$ 计数初值绝对是大于1的，也就是 $$N &#x3D; \frac{F_{osc}}{f}$$如果计数器计数初值超过 FFFFH，说明 Fosc 太大，可以多设置一个定时器，用那个定时器的 OUT 代替晶振作为超过限制计数器的 CLK信号输入： $$ N &#x3D; \frac{f_{new}}{f}">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://jav1ki4n.github.io/img/i4N.png">
<meta property="article:published_time" content="2025-10-20T16:05:17.811Z">
<meta property="article:modified_time" content="2025-10-20T16:09:34.155Z">
<meta property="article:author" content="i4N">
<meta property="article:tag" content="embedded,STM32">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://jav1ki4n.github.io/img/i4N.png"><script type="application/ld+json">{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "微机原理（LEGACY）",
  "url": "http://jav1ki4n.github.io/2025/10/21/%E5%BE%AE%E6%9C%BA%E6%80%BB%E7%BB%93/",
  "image": "http://jav1ki4n.github.io/img/i4N.png",
  "datePublished": "2025-10-20T16:05:17.811Z",
  "dateModified": "2025-10-20T16:09:34.155Z",
  "author": [
    {
      "@type": "Person",
      "name": "i4N",
      "url": "http://jav1ki4n.github.io"
    }
  ]
}</script><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://jav1ki4n.github.io/2025/10/21/%E5%BE%AE%E6%9C%BA%E6%80%BB%E7%BB%93/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css?v=5.5.1"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@7.1.0/css/all.min.css"><script>
    (() => {
      
    const saveToLocal = {
      set: (key, value, ttl) => {
        if (!ttl) return
        const expiry = Date.now() + ttl * 86400000
        localStorage.setItem(key, JSON.stringify({ value, expiry }))
      },
      get: key => {
        const itemStr = localStorage.getItem(key)
        if (!itemStr) return undefined
        const { value, expiry } = JSON.parse(itemStr)
        if (Date.now() > expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return value
      }
    }

    window.btf = {
      saveToLocal,
      getScript: (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        Object.entries(attr).forEach(([key, val]) => script.setAttribute(key, val))
        script.onload = script.onreadystatechange = () => {
          if (!script.readyState || /loaded|complete/.test(script.readyState)) resolve()
        }
        script.onerror = reject
        document.head.appendChild(script)
      }),
      getCSS: (url, id) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onload = link.onreadystatechange = () => {
          if (!link.readyState || /loaded|complete/.test(link.readyState)) resolve()
        }
        link.onerror = reject
        document.head.appendChild(link)
      }),
      addGlobalFn: (key, fn, name = false, parent = window) => {
        if (!false && key.startsWith('pjax')) return
        const globalFn = parent.globalFn || {}
        globalFn[key] = globalFn[key] || {}
        globalFn[key][name || Object.keys(globalFn[key]).length] = fn
        parent.globalFn = globalFn
      }
    }
  
      
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode

      const theme = saveToLocal.get('theme')
    
          theme === 'dark' ? activateDarkMode() : theme === 'light' ? activateLightMode() : null
        
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        document.documentElement.classList.toggle('hide-aside', asideStatus === 'hide')
      }
    
      
    const detectApple = () => {
      if (/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)) {
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
  
    })()
  </script><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":false,"highlightMacStyle":true},
  copy: {
    success: '复制成功',
    error: '复制失败',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'null',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid@4.12.0/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyloadPlugin: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '微机原理（LEGACY）',
  isHighlightShrink: false,
  isToc: true,
  pageType: 'post'
}</script><meta name="generator" content="Hexo 8.0.0"></head><body><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url(/img/bck.png);"><nav id="nav"><span id="blog-info"><a class="nav-site-title" href="/"><img class="site-icon" src="/img/i4N_small.png" alt="Logo"><span class="site-name">Fusyōn.</span></a><a class="nav-page-title" href="/"><span class="site-name">微机原理（LEGACY）</span><span class="site-name"><i class="fa-solid fa-circle-arrow-left"></i><span>  返回首页</span></span></a></span><div id="menus"></div></nav><div id="post-info"><h1 class="post-title">微机原理（LEGACY）</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2025-10-20T16:05:17.811Z" title="发表于 2025-10-21 00:05:17">2025-10-21</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2025-10-20T16:09:34.155Z" title="更新于 2025-10-21 00:09:34">2025-10-21</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="container post-content" id="article-container"><hr>
<h2 id="定时器"><a href="#定时器" class="headerlink" title="定时器"></a>定时器</h2><h3 id="8253-初始化"><a href="#8253-初始化" class="headerlink" title="8253 初始化"></a>8253 初始化</h3><p>首先计算计数初值，晶振频率为 $F_{osc}$，目标信号频率是 $f$</p>
<p>计数初值绝对是大于1的，也就是 $$N &#x3D; \frac{F_{osc}}{f}$$<br>如果计数器计数初值超过 <code>FFFFH</code>，说明 <code>Fosc</code> 太大，可以多设置一个定时器，用那个定时器的 <code>OUT</code> 代替晶振作为超过限制计数器的 <code>CLK</code>信号输入：</p>
<p>$$ N &#x3D; \frac{f_{new}}{f} $$</p>
<p>配置一个定时 &#x2F; 计数器：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">CONFIG:</span><br><span class="line">	MOV DX &lt;控制字地址，一般是最后的端口地址&gt;</span><br><span class="line">	MOV AL &lt;控制字内容，包括 选中哪个定时器 以及 定时器的工作方式 (输出波形)&gt;</span><br><span class="line">	OUT DX AL</span><br><span class="line"></span><br><span class="line">	MOV DX &lt;定时器的数据输入地址，一般是前三个端口地址，按 T0,T1,T2&gt;</span><br><span class="line">	MOV AL &lt;计数初值 N，16位一次装填就可以&gt; </span><br><span class="line">	OUT DX AL</span><br></pre></td></tr></table></figure>

<p>配置 n 个：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">CONFIG1 - 按照上面的格式</span><br><span class="line">CONFIG2</span><br><span class="line">CONFIG3</span><br></pre></td></tr></table></figure>

<hr>
<h3 id="80C51-初始化"><a href="#80C51-初始化" class="headerlink" title="80C51 初始化"></a>80C51 初始化</h3><p>首先计算初值，晶振不能直接用。</p>
<p>需要$$N &#x3D; \frac{F_{osc}}{12f}$$</p>
<p>这是因为 一个<code>机器周期</code> &#x2F; <code>总线周期</code> 等于 12 个<code>晶振周期</code>，<br>所以：</p>
<ul>
<li>周期来计算定时器初值，要将周期 ×12；</li>
<li>频率则需要将频率 ÷12。</li>
</ul>
<p>这之后，由于51的定时器是一个 <code>减1计数器</code>,还需要：</p>
<p>$$ X &#x3D; 2^{16} - N $$<br>得到计数初值 <code>X</code>。</p>
<hr>
<p>80C51 的定时器可以用 中断或者查询模式实现, 配置时可以直接使用寄存器名字比如 <code>TMOD</code>, 不像86一样需要 <code>OUT</code>。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">	  ORG 0000H ;设定起始地址</span><br><span class="line"> ~--- AJMP MAIN ;去执行主函数（该指令地址为0000H，上电就跳转）</span><br><span class="line">|	  </span><br><span class="line">|	  ORG 00B0H ;定时器0中断向量</span><br><span class="line">|	  LJMP CTC0 ;长跳到 ISR</span><br><span class="line">|	                                             </span><br><span class="line">|	  ORG 0030H ;主函数的地址</span><br><span class="line">↓</span><br><span class="line">MAIN: MOV TMOD &lt;控制字，一次同时控制两个定时器&gt;      </span><br><span class="line"></span><br><span class="line">	  MOV TH0 &lt;计数初值高位&gt;                             </span><br><span class="line">	  MOV TL0 &lt;计数初值低位&gt;</span><br><span class="line">	  </span><br><span class="line">	  SETB EA   ;启用总中断</span><br><span class="line">	  SETB ET0  ;启用定时器中断</span><br><span class="line">	  </span><br><span class="line">	  SETB TR0  ;启动定时器</span><br><span class="line">	  SJMP $    ;启动之后等待中断</span><br><span class="line"></span><br><span class="line">CTC0: </span><br><span class="line">	  &lt;执行逻辑代码&gt;</span><br><span class="line">	  MOV TH0   ;执行完之后说明中断完成，开始重装(如果需要的话)</span><br><span class="line">	  MOV TL0</span><br><span class="line">	  SETB TR0  ;重启定时器</span><br><span class="line">	  </span><br><span class="line">	  RETI</span><br><span class="line">	  </span><br><span class="line">	  END       ;结束程序</span><br></pre></td></tr></table></figure>

<p>中断的好处是自动检测是否溢出以及清除溢出标志位。</p>
<p>使用查询方式则依赖 <code>LOOP</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">	   ORG 0000H</span><br><span class="line">	   AJMP MAIN</span><br><span class="line">	   ORG 0030H</span><br><span class="line"></span><br><span class="line">MAIN:  MOV TMOD..</span><br><span class="line">LOOP:  MOV TH0 ..</span><br><span class="line">	   MOV TL0 ..</span><br><span class="line"></span><br><span class="line">	   SETB TR0</span><br><span class="line">	   </span><br><span class="line">	   JNB TF0,$  ;需要自己检测并清除</span><br><span class="line">	   CLR TF0</span><br><span class="line">	   </span><br><span class="line">	   &lt;逻辑代码&gt;</span><br><span class="line">	</span><br><span class="line">	   SJMP LOOP  ;相当于进行重装重启动，而这些在中断是交给 ISR 做的</span><br></pre></td></tr></table></figure>

<p>关于80C51 几种特殊信号波形的产生：</p>
<p>方波的 <code>&lt;逻辑代码&gt;</code> 可以写成 <code>CPL Px.x</code> 。</p>
<p>负脉冲则要复杂一些：</p>
<p>对于一个 <code>2s</code> 周期，脉宽 <code>50ms</code> 的负脉冲波，真正需要参与计算的其实是 <code>50ms</code>，然后再将定时循环 <code>2s/50ms - 1 = 400 - 1 = 399</code> 次完成整个周期。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">                          ______</span><br><span class="line">__________________________|    |___________________________</span><br><span class="line">                          ←50ms→       ←2s - 500ms→</span><br><span class="line">                          </span><br><span class="line">	  MOV TMOD #01H ;配置T0工作在方式1</span><br><span class="line">	  MOV R7 #399</span><br><span class="line"></span><br><span class="line">LOOP: SETB P1.3 ;在P1.3首先生成一个高电平，这个高电平的持续时间就是脉宽</span><br><span class="line">	  ACALL NT0 ;重装计数值，开始定时50ms</span><br><span class="line">	  </span><br><span class="line">	  CLR P1.3  ;清0，这就算完成了一个脉冲了</span><br><span class="line">	  </span><br><span class="line">WAIT: ACALL NT0 ;距离下一次高电平还有一个（400-1 = 399）个定时周期</span><br><span class="line">	  DJNZ R7 LOOP ; 计数未到399，总共未达到2s，继续 WAIT 保持低电平</span><br><span class="line">	  </span><br><span class="line">	  AJMP LOOP ; 这个周期结束，开始准备下一个波形   </span><br><span class="line"></span><br><span class="line">NTO: MOV TH0,#03H</span><br><span class="line">	 MOV TL0,#CBH</span><br><span class="line">	 SETB TR0</span><br><span class="line">	 JNB TF0,$</span><br><span class="line">	 CLR TF0</span><br></pre></td></tr></table></figure>

<hr>
<h2 id="8255"><a href="#8255" class="headerlink" title="8255"></a>8255</h2><p>8255 端口地址对应  <code>A</code> <code>B</code> <code>C</code> <code>CTRL REG</code>, 尽管口之间有编组，寻址的时候还是单独分开了。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">MOV DX &lt;控制字地址&gt;</span><br><span class="line">MOV AL &lt;控制字，可配置位操作与组的同时配置&gt;</span><br><span class="line">OUT DX AL</span><br></pre></td></tr></table></figure>

<p>如果想要输出数据了，比如 &#96;PC4 &#x3D; 0, PC7 &#x3D; 1:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">MOV AL &lt;控制字，切换到位操作&gt;</span><br><span class="line">OUT DX AL</span><br></pre></td></tr></table></figure>

<p>如果想要读取数据，很遗憾不能单口读取 </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">MOV DX &lt;控制字地址&gt;</span><br><span class="line">MOV AL &lt;控制字，改为输入模式&gt;</span><br><span class="line">OUT DX AL</span><br><span class="line"></span><br><span class="line">MOV DX &lt;比如这里是C口地址&gt;</span><br><span class="line">IN AL DX &lt;从C口读取8位数据放在AL&gt;</span><br></pre></td></tr></table></figure>

<hr>
<h2 id="8259A"><a href="#8259A" class="headerlink" title="8259A"></a>8259A</h2><p>8259 的两个端口地址管两种控制字</p>
<p><code>ICW1  ICW2  ICW4</code> 一般必须，<code>ICW3  OCW1   OCW2   OCW3</code> 看情况。</p>
<p><code>ICW1</code>  使用第一个端口地址，<code>ICW2  ICW4</code> 使用第二个</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">MOV DX &lt;控制字地址 20H&gt;</span><br><span class="line">MOV AL &lt;控制字 ICW1&gt;</span><br><span class="line">OUT DX AL</span><br><span class="line"></span><br><span class="line">MOV DX &lt;控制字地址 21H&gt;</span><br><span class="line">MOV AL &lt;中断向量码&gt;</span><br><span class="line">OUT DX AL</span><br><span class="line"></span><br><span class="line">MOV AL &lt;ICW4&gt;</span><br><span class="line">OUT DX AL</span><br><span class="line"></span><br><span class="line">HLT</span><br></pre></td></tr></table></figure>

<hr>
<table>
<thead>
<tr>
<th>分类</th>
<th>8086 寻址方式</th>
<th>8051 寻址方式</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td><strong>立即寻址</strong></td>
<td><code>MOV AX, 1234H</code></td>
<td><code>MOV A, #25H</code></td>
<td>数据直接写在指令中</td>
</tr>
<tr>
<td><strong>寄存器寻址</strong></td>
<td><code>MOV AX, BX</code></td>
<td><code>MOV A, R0</code></td>
<td>操作数是寄存器</td>
</tr>
<tr>
<td><strong>直接寻址（地址寻址）</strong></td>
<td><code>MOV AX, [1234H]</code></td>
<td><code>MOV A, 30H</code></td>
<td>地址写在指令中，访问内存</td>
</tr>
<tr>
<td><strong>寄存器间接寻址</strong></td>
<td><code>MOV AX, [BX]</code></td>
<td><code>MOV A, @R0</code></td>
<td>地址存储在寄存器中</td>
</tr>
<tr>
<td><strong>寄存器间接+位移</strong></td>
<td><code>MOV AX, [BX+SI]</code> &#x2F; <code>[BX+4]</code></td>
<td>-</td>
<td>8086支持较复杂的寄存器变址寻址</td>
</tr>
<tr>
<td><strong>基址变址寻址</strong></td>
<td><code>MOV AX, [BX+SI+10H]</code></td>
<td>-</td>
<td>8086强项，用于结构体、数组访问</td>
</tr>
<tr>
<td><strong>相对寻址</strong></td>
<td><code>JMP LABEL</code> （<code>JMP SHORT</code> 等）</td>
<td><code>SJMP LABEL</code></td>
<td>用于跳转指令，相对当前 PC</td>
</tr>
<tr>
<td><strong>位寻址</strong></td>
<td>-</td>
<td><code>SETB P1.0</code>、<code>CLR 30H</code> 等</td>
<td>8051 支持专用的位寻址区域（20H–2FH）和部分 SFR</td>
</tr>
<tr>
<td><strong>I&#x2F;O 寻址</strong></td>
<td><code>IN AL, 60H</code> &#x2F; <code>OUT 60H, AL</code></td>
<td>使用内存映射方式：<code>MOV P1, A</code></td>
<td>8086 I&#x2F;O 与内存分离，8051 I&#x2F;O 与内存统一寻址空间</td>
</tr>
<tr>
<td><strong>外部RAM寻址</strong></td>
<td><code>[DS:offset]</code>、<code>[ES:offset]</code></td>
<td><code>MOVX A, @DPTR</code> &#x2F; <code>MOVX A, @R0</code></td>
<td>都需要特殊指令访问外部存储</td>
</tr>
<tr>
<td><strong>代码存储器访问</strong></td>
<td><code>CALL</code>, <code>JMP</code>, <code>INT</code> 等</td>
<td><code>MOVC A, @A+DPTR</code></td>
<td>都通过特定寻址机制访问 ROM（代码存储器）</td>
</tr>
</tbody></table>
<h3 id="两种定时初值溢出题型"><a href="#两种定时初值溢出题型" class="headerlink" title="两种定时初值溢出题型"></a>两种定时初值溢出题型</h3><h4 id="8086"><a href="#8086" class="headerlink" title="8086"></a>8086</h4><p>策略：改变 CLK 输入为另一个的输出, 两个定时器的模式要保持一致（输出波形）。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">MOV DX ...</span><br><span class="line">MOV AL ...    ;TIMER0 CFG</span><br><span class="line">MOV DX AL</span><br><span class="line"></span><br><span class="line">MOV DX ...</span><br><span class="line">MOV AL ...</span><br><span class="line">OUT DX AL     ;TIMER0 LOAD</span><br><span class="line">MOV AL ...</span><br><span class="line">OUT DX AL                </span><br><span class="line"></span><br><span class="line">MOV DX ...</span><br><span class="line">MOV AL ...    ;TIMER1 CFG</span><br><span class="line">MOV DX AL</span><br><span class="line"></span><br><span class="line">MOV DX ...</span><br><span class="line">MOV AL ...</span><br><span class="line">OUT DX AL     ;TIMER1 LOAD</span><br><span class="line">MOV AL ...</span><br><span class="line">OUT DX AL    </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h3 id="51"><a href="#51" class="headerlink" title="51"></a>51</h3><p>策略：使用 LOOP ,多次小中断 –&gt; 累积大中断</p>
<p>80c51,12Mhz，产生10ms中断，p1.7输出2s方波，用中断实现。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">          ORG 0000H         ; 程序起始</span><br><span class="line">          AJMP MAIN         ; 跳转到主函数</span><br><span class="line"></span><br><span class="line">          ORG 000BH         ; 定时器0中断向量入口</span><br><span class="line">          LJMP TIMER0_ISR   ; 跳转到中断服务程序</span><br><span class="line"></span><br><span class="line">MAIN:     MOV TMOD, #01H    ; 定时器0工作在模式1（16位定时）</span><br><span class="line">          MOV TH0, #0D8H    ; 装载初值高位</span><br><span class="line">          MOV TL0, #0F0H    ; 装载初值低位</span><br><span class="line"></span><br><span class="line">          MOV R7, #100      ; 设置翻转周期（100次中断翻转一次）</span><br><span class="line"></span><br><span class="line">          SETB EA           ; 开总中断</span><br><span class="line">          SETB ET0          ; 开定时器0中断</span><br><span class="line">          SETB TR0          ; 启动定时器0</span><br><span class="line"></span><br><span class="line">LOOP:     SJMP LOOP         ; 主程序空转</span><br><span class="line"></span><br><span class="line">;--------------------------------------</span><br><span class="line"></span><br><span class="line">TIMER0_ISR:</span><br><span class="line">          CLR TR0           ; 先停定时器</span><br><span class="line"></span><br><span class="line">          MOV TH0, #0D8H    ; 重装初值</span><br><span class="line">          MOV TL0, #0F0H</span><br><span class="line"></span><br><span class="line">          DJNZ R7, SKIP     ; 中断计数器减1，如果没到就跳过翻转</span><br><span class="line">          CPL P1.7          ; 翻转P1.7</span><br><span class="line">          MOV R7, #100      ; 重新设置中断计数器</span><br><span class="line"></span><br><span class="line">SKIP:     SETB TR0          ; 重启定时器</span><br><span class="line">          RETI              ; 中断返回</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>


<h1 id="我草拟吗的电子信息"><a href="#我草拟吗的电子信息" class="headerlink" title="我草拟吗的电子信息"></a><span style="color: #FF0000;">我</span><span style="color: #FF7F00;">草</span><span style="color: #FFFF00;">拟</span><span style="color: #00FF00;">吗</span><span style="color: #00FFFF;">的</span><span style="color: #0000FF;">电</span><span style="color: #4B0082;">子</span><span style="color: #8B00FF;">信</span><span style="color: #FF69B4;">息</span></h1><h4 id="我草-拟吗的。电子，信息-1。"><a href="#我草-拟吗的。电子，信息-1。" class="headerlink" title="我草, 拟吗的。电子，信息 1。"></a>我草, 拟吗的。电子，信息 <sup>1</sup>。</h4><hr>
<p> <sup>[1]</sup>: 我草拟吗的电子信息</p>
<blockquote>
<p><span style="font-family: 'Source Han Serif', '思源宋体', serif; font-style: italic;">我草拟吗的电子信息。</p>
</span></blockquote>
<blockquote>
<p><span style="font-family: 'Georgia'; font-style: italic;"> Fuck you EIE  </span></p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">我草 (拟,吗,的)</span><br><span class="line">&#123;</span><br><span class="line">	电子信息;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>我</th>
<th>草</th>
<th>拟</th>
<th>吗</th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>的</td>
<td>电</td>
<td>子</td>
<td>信</td>
<td>息</td>
</tr>
<tr>
<td>$Equation\space1.1:$</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>$$</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Fuck\space you\space EIE &#x3D; \int_{草}^{我}\frac{拟^{吗}} {的_{电子} *（信息）} \space</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>$$</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody></table>
<p><a href="">我草拟吗的电子信息</a></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody><tr>
<td>1.24</td>
<td>1.48</td>
<td>1.68</td>
<td>1.88</td>
<td>2</td>
<td>2.12</td>
<td>2.2</td>
<td>2.28</td>
<td>2.68</td>
<td>3.2</td>
<td>3.52</td>
</tr>
<tr>
<td>1.44</td>
<td>1.8</td>
<td>2.16</td>
<td>2.52</td>
<td>2.76</td>
<td>3.04</td>
<td>3.32</td>
<td>3.56</td>
<td>4.08</td>
<td>4.24</td>
<td>4.32</td>
</tr>
<tr>
<td>0.7</td>
<td>0.84</td>
<td>0.94</td>
<td>1.02</td>
<td>1.06</td>
<td>1.1</td>
<td>1.12</td>
<td>1.18</td>
<td>1.26</td>
<td>1.42</td>
<td>1.54</td>
</tr>
</tbody></table>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="http://jav1ki4n.github.io">i4N</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="http://jav1ki4n.github.io/2025/10/21/%E5%BE%AE%E6%9C%BA%E6%80%BB%E7%BB%93/">http://jav1ki4n.github.io/2025/10/21/%E5%BE%AE%E6%9C%BA%E6%80%BB%E7%BB%93/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来源 <a href="http://jav1ki4n.github.io" target="_blank">Fusyōn.</a>！</span></div></div><div class="tag_share"><div class="post-share"><div class="social-share" data-image="/img/i4N.png" data-sites="facebook,x,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.6/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.6/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><a class="pagination-related" href="/2025/11/01/%E4%BA%8C%E3%80%87%E4%BA%8C%E4%BA%94%20%E6%9C%88%E5%BA%A6%E8%AE%B0%E5%BD%95%20%E5%85%B6%E5%8D%81/" title="二〇二五 月度记录 其十"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info"><div class="info-1"><div class="info-item-1">上一篇</div><div class="info-item-2">二〇二五 月度记录 其十</div></div><div class="info-2"><div class="info-item-1"> OctoberOct.1st ~ Oct.6th 家中摆烂。 将驱动用 C++ 部分重构了一遍，但是 Keil Assistant 配合编译器使用总是会报各种各样的错误，而且使用 Keil 实在令人抓耳挠腮，遂想要重新配一个独立的工具链。  Oct.7th 咨询了一下土澳和加拿大留学的相关事宜，大概梳理了一下后续的一年多时间应该要做什么。总之先找到老师进组科研吧。 配置工具链。  Oct.8th 配置好了工具链，在 STM32F411CEU6 下进行了验证。  1CubeMx - MSYS2 - arm-none-eabi-gcc - ninja - openocd   Oct. 9th ~ Oct.13thC mixing with C++ 出了问题。 萎靡不振。 Oct.13th ~ Oct.15th将博客重建了一下，主题换成了 Butterfly ，各种资源先轻量化一点，日后再修缮。 换到了 Clion 上解决了部分工具链配置上的问题，但是这一块混合编译的信息量真的不小。回归嵌入式之后 C++ 这边暂时没有学新的特性了，一边实践一边理解吧。 Oct.16 - Oct.20...</div></div></div></a><a class="pagination-related" href="/2025/10/21/%E5%BE%AE%E6%9C%BA%E5%8E%9F%E7%90%86/" title="微机原理(LEGACY)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-right"><div class="info-1"><div class="info-item-1">下一篇</div><div class="info-item-2">微机原理(LEGACY)</div></div><div class="info-2"><div class="info-item-1"> Von Noemann 计算机核心思想：存储程序控制  程序由按序排列的指令组成，保存在 存储器 之中 指令和数据由 二进制 编码 指令的执行按照 在存储器中的存储顺序 控制器控制程序与数据的 存取，也控制 执行 所有的执行经过运算器，运算器是核心。  从真值到其他码制   极性 真值 原码 反码 补码 移码 &#x2F; 增码    + +数值 0+数值 与原码相同 与原码相同 补码符号位取反   - -数值 1+数值 除符号位1以外全部取反 反码+1 补码符号位取反     若要从 N 的 补码 得到 -N 的 补码，对 ±N 的 补码 包括符号位在内 的所有位取反后+1（0x01）即可。N 的极性不作规定。  如果采用 $[-N]_{原}$  的表示方法，此时正数与负数的符号位交换（也就是正数的符号位变成1），那么表格中的极性也应当交换。    有关小数的码制表示：    真值 原码 解释    +0.1001 0.1001 小数的整数位是0，在进行转换时符号位直接占据了这一位置   - 0.1001 1.1001 由于负数是1，这里看的更加明显   基于补码的运算手段补...</div></div></div></a></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info text-center"><div class="avatar-img"><img src="/img/i4N.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info-name">i4N</div><div class="author-info-description"></div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">6</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/jav1ki4N"><i class="fab fa-github"></i><span>Github</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>关于 / Aboout</span></div><div class="announcement_content">Ain't nothing new here</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9A%E6%97%B6%E5%99%A8"><span class="toc-number">1.</span> <span class="toc-text">定时器</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#8253-%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="toc-number">1.1.</span> <span class="toc-text">8253 初始化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#80C51-%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="toc-number">1.2.</span> <span class="toc-text">80C51 初始化</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8255"><span class="toc-number">2.</span> <span class="toc-text">8255</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8259A"><span class="toc-number">3.</span> <span class="toc-text">8259A</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%A4%E7%A7%8D%E5%AE%9A%E6%97%B6%E5%88%9D%E5%80%BC%E6%BA%A2%E5%87%BA%E9%A2%98%E5%9E%8B"><span class="toc-number">3.1.</span> <span class="toc-text">两种定时初值溢出题型</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#8086"><span class="toc-number">3.1.1.</span> <span class="toc-text">8086</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#51"><span class="toc-number">3.2.</span> <span class="toc-text">51</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%88%91%E8%8D%89%E6%8B%9F%E5%90%97%E7%9A%84%E7%94%B5%E5%AD%90%E4%BF%A1%E6%81%AF"><span class="toc-number"></span> <span class="toc-text">我草拟吗的电子信息</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%88%91%E8%8D%89-%E6%8B%9F%E5%90%97%E7%9A%84%E3%80%82%E7%94%B5%E5%AD%90%EF%BC%8C%E4%BF%A1%E6%81%AF-1%E3%80%82"><span class="toc-number">0.0.1.</span> <span class="toc-text">我草, 拟吗的。电子，信息 1。</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/11/01/%E4%BA%8C%E3%80%87%E4%BA%8C%E4%BA%94%20%E6%9C%88%E5%BA%A6%E8%AE%B0%E5%BD%95%20%E5%85%B6%E5%8D%81/" title="二〇二五 月度记录 其十">二〇二五 月度记录 其十</a><time datetime="2025-11-01T07:52:34.638Z" title="发表于 2025-11-01 15:52:34">2025-11-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/10/21/%E5%BE%AE%E6%9C%BA%E6%80%BB%E7%BB%93/" title="微机原理（LEGACY）">微机原理（LEGACY）</a><time datetime="2025-10-20T16:05:17.811Z" title="发表于 2025-10-21 00:05:17">2025-10-21</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/10/21/%E5%BE%AE%E6%9C%BA%E5%8E%9F%E7%90%86/" title="微机原理(LEGACY)">微机原理(LEGACY)</a><time datetime="2025-10-20T16:05:17.808Z" title="发表于 2025-10-21 00:05:17">2025-10-21</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/10/13/%E5%9C%A8%20Clion%20%E4%B8%AD%E4%BD%BF%E7%94%A8C%E4%B8%8EC++%E6%B7%B7%E5%90%88%E5%BC%80%E5%8F%91%20STM32/" title="在 Clion 中使用 C/C++ 混合开发 STM32">在 Clion 中使用 C/C++ 混合开发 STM32</a><time datetime="2025-10-13T12:23:15.899Z" title="发表于 2025-10-13 20:23:15">2025-10-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/10/12/2025/" title="2025 月度记录 其九">2025 月度记录 其九</a><time datetime="2025-10-12T06:25:58.373Z" title="发表于 2025-10-12 14:25:58">2025-10-12</time></div></div></div></div></div></div></main><footer id="footer"><div class="footer-other"><div class="footer-copyright"><span class="copyright">&copy;&nbsp;2025 By i4N</span><span class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo 8.0.0</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly 5.5.1</a></span></div><div class="footer_custom_text">Le cadavre exquis boira le vin nouveau.</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js?v=5.5.1"></script><script src="/js/main.js?v=5.5.1"></script><script src="/js/tw_cn.js?v=5.5.1"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>